## What's broken MaskedLinearOperator.to(device=...) crashes with AttributeError when called with a device but no dtype (e.g. .to(device="cpu")). The base LinearOperator.to() handles device-only moves fine; this subclass override (added to keep bool masks from being cast to float) regresses that path.#133
Open
devteamaegis wants to merge 1 commit into
Open
## What's broken MaskedLinearOperator.to(device=...) crashes with AttributeError when called with a device but no dtype (e.g. .to(device="cpu")). The base LinearOperator.to() handles device-only moves fine; this subclass override (added to keep bool masks from being cast to float) regresses that path.#133devteamaegis wants to merge 1 commit into
MaskedLinearOperator.to(device=...) crashes with AttributeError when called with a device but no dtype (e.g. .to(device="cpu")). The base LinearOperator.to() handles device-only moves fine; this subclass override (added to keep bool masks from being cast to float) regresses that path.#133devteamaegis wants to merge 1 commit into
Conversation
_to_helper returns dtype=None when only a device is passed. The MaskedLinearOperator.to override then accessed dtype.is_floating_point unconditionally, raising AttributeError. Guard for dtype is None so a device-only move keeps masks boolean, matching the base to() behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why it happens
_to_helperreturnsdtype=Nonewhen only a device is supplied, but the override evaluatesarg.dtype.is_floating_point == dtype.is_floating_pointunconditionally, sodtype.is_floating_pointraises whendtype is None.Fix
Guard with
dtype is not None: when no dtype is requested, move every arg (including masks) by device only, preserving the bool dtype — matching baseto().Test
Added
test_to_device(device-only move keeps masks boolean). Fails before (AttributeError), passes after; full masked-operator suite (167) green.